<!DOCTYPE HTML><html>
<head>
<? echo $h->meta($title, $kwd, $dpn); ?>
<? require_once("lib.php"); ?>
<script src="<?=$ecom?>/js/jquery.validate.js" type="text/javascript"></script>
<script src="<?=$ecom?>/js/jquery.metadata.js" type="text/javascript"></script>
</head>

<body>
<? include_once("header.php"); ?>
<div id="wrap">
    <div id="main">
        <ul class="flow_step">
            <li><?=WEB_MY_CART?></li>
            <li><?=WEB_FILL_CHECK_ORDER?></li>
            <li class="step1"><?=WEB_SUCCESS_SUBMIT_ORDER?></li>
        </ul><!--end flow_step-->
        <div class="clear"></div>
        <div class="payment_info">
            <?
            $receive_info='';
            if(! $are_virtual){
                $address_book_id = $order['address_book_id'];
                $address = $address_book->get_row($address_book_id);
                $tem_country=OVERSEA?$country->get_name($address['country_id'],$lang):'';
                $tem_province=$address['province_id']==0?'':$province->get_name($address['province_id'],$lang);
                $tem_city=$address['city_id']==0?'':$city->get_name($address['city_id'],$lang);
                $tem_county=$address['county_id']==0?'':$county->get_name($address['county_id'],$lang);
                $receive_info=$tem_country.' '.$tem_province.' '.$tem_city.' '.$tem_county.' '.$address['street'].', &nbsp; '.$address['contact_name'].' '.$address['mobile'];
            }
            ?>
            <div style="">
                <div class="left" style="width: 60%">
                    <?echo WEB_ORDER_SUBMIT_SUCCESS_TIP ?><br />
                    <?echo WEB_ORDER_REF_NO.': '.$ref_no;?><br />
                    <?echo WEB_DELIVERY_INFO.': '.$receive_info;?>
                </div>
                <div class="right tright" style="width: 30%"><?echo WEB_SHOULD_PAY.': '.$tem_currency_code.'<span class="span_total_price">'.$order['total_price'].'</span>';?></div>
                <div class="clear"></div>
            </div>
        </div>
        <? echo $h->form('checkout.php',0,'order_form'); ?>
        <div id="pay_box">
			<div id="order_title"><?=WEB_PAYMENT_METHOD?></div>
            <table class="table_cart" cellpadding="0" cellspacing="0">
                <tbody>
                <tr>
                    <td>
			<div class="order_payment_area">
				<?
                if(isset($order['order_price'])) echo $h->hidden('order_price',$order['order_price'],'order_price');
                if(isset($order['total_price'])) echo $h->hidden('total_price',$order['total_price'],'total_price');
                if(isset($order['shipment_fee'])) echo $h->hidden('shipment_cost',$order['shipment_fee'],'shipment_cost');
                if(isset($order['customer_id'])) echo $h->hidden('customer_id',$order['customer_id'],'customer_id');
                if(isset($order['currency_id'])) echo $h->hidden('currency_id',$order['currency_id'],'currency_id');
                if(isset($order['are_virtual'])) echo $h->hidden('is_virtual',$order['are_virtual'],'');
                if(isset($order['with_tax'])) echo $h->hidden('with_tax',$order['with_tax'],'with_tax');
                if(isset($order['email'])) echo $h->hidden('email',$order['email'],'email');
                if(isset($order['tax'])) echo $h->hidden('tax',$order['tax'],'input_tax');
//                if(isset($str_order)) echo $h->hidden('str_order', $str_order, '');
                if(isset($ref_no)) echo $h->hidden('ref_no', $ref_no, '');
                echo $h->hidden('wallet_amount',0,'wallet_amount');
					$str=''; $str2=''; $str3 = '';$k=0;
				foreach($arr_payment as $key=>$row){
                    if( $row['id']==7){
                        $str3='
                        <li style="width: 100%" class="my_walllet_payment">
                            <div class="my_wallet">
                                <input id="pay_wallet" class="use_balance" type="checkbox" name="use_balance" value="7" />
                                <label class="vam" for="pay_wallet">'.$row['name_'.$lang].'</label>
                                <input oninput="OnInput(event)" onpropertychange="OnPropChanged(event)" type="text" name="wallet" value="0" style="width: 30px; margin-left: 10px" maxlength="10" class="wallet">CNY
                                <label class="vam" for="pay_wallet" style="margin-left: 10px">余额：<span class="usable_balance blue">'.$customer_info['usable_balance'].'</span></label>
                            </div><br><br>
                            <div style="margin-left: 20px">*如果选择"我的钱包"付款，则不能组合"货到付款"方式</div>
                        </li>
                        ';
                    }else{
						$checked='';
						if($k==0)$checked=' checked ';
						if(!empty($row['pic'])) $str.='<li>
					<div class="payment_area"><input '.$checked.' id="pay_'.$k.'" class="radio" type="radio" name="payment_method" value="'.$row['id'].'"></input>
						<label class="vam" for="pay_'.$k.'"><img src="upload/'.$row['pic'].'" height="36" /></label>
					</div>
				</li>';
						else $str2.='<li>
					<div class="payment_area">
						<input id="pay_'.$k.'" class="radio" type="radio" name="payment_method" value="'.$row['id'].'"></input>
						<label class="vam" for="pay_'.$k.'">'.$row['name_'.$lang].'</label>
					</div>
				</li>';
						$k++;
                    }
					}
				?>
                <?if($str3!=''){?>
                    <ul class="payment_bank_list">
                        <?echo $str3;?>
                    </ul>
                    <div class="clear"></div>
                <?}?>
				<? if($str!=''){ ?>
				<div class="explain"><b><?=WEB_ONLINE_PAYMENT?>： </b></div>
				<ul class="payment_bank_list">
					<? echo $str ?>
				</ul><!--payment_bank_list end-->
                <div class="clear"></div>
				<? } ?>
				<? if($str2!=''){ ?>
				<div class="explain"><b><?=WEB_OTHER_METHOD?>： </b></div>
				<ul class="payment_bank_list">
					<? echo $str2 ?>
				</ul><!--payment_bank_list end-->
                <div class="clear"></div>
				<? } ?>
			</div><!--order_payment_area end-->
            </td></tbody>
            <tfoot><tr><td class="nobb">
                <div class="payment_button tright">
                    <a class="button button_big bg_red" onclick="order_submit()"><?=WEB_SUBMIT_PAYMENT?></a>
                </div>
            </td><tr></tfoot>
            </table>
        </div><!--pay_box end-->
        <? echo $h->former(); ?>
    </div><!--main end-->
</div><!--wrap end-->
<? include("footer.php"); ?>
<script type="text/javascript">
    var total_price = <?=$order['total_price']?>;
    var use_balance = <?=$customer_info['usable_balance']?>;
    var wallet_amount = 0;
    $(function(){
        var w = 0;
        $('input:checkbox[name="use_balance"]').click(function(){
            if(!w){
                $('input:checkbox[name="use_balance"]').prop('checked', true);
                $('input:radio[name="payment_method"]').each(function(){
                    if($(this).val() == 5){
                        $(this).attr('disabled', true);
                        $(this).attr('checked', false);
                        $(this).parent().css('color','#cccccc');
                    }
                });
                w = 1;
            }else{
                $('input:checkbox[name="use_balance"]').prop('checked', false);
                $('input:radio[name="payment_method"]').each(function(){
                    if($(this).val() == 5){
                        $(this).attr('disabled', false);
                        $(this).parent().css('color','#000000');
                    }
                });
                $('.span_total_price').html(total_price);
                $('.span_wallet_amount').html(wallet_amount);
                $('.usable_balance').html(use_balance);
                $('input:text[name="wallet"]').val(0);
                $('input:hidden[name="total_price"]').val(total_price);
                $('input:hidden[name="wallet_amount"]').val(0);
                w = 0;
            }
        });


        $('input:text[name="wallet"]').click(function(){
            $('input:checkbox[name="use_balance"]').prop('checked', true);
//            $('input:checkbox[name="use_balance"]').each(function(){$(this).attr('checked', 'checked')});
            $('input:radio[name="payment_method"]').each(function(){
                if($(this).val() == 5){
                    $(this).attr('disabled', true);
                    $(this).attr('checked', false);
                    $(this).parent().css('color','#cccccc');
                }
            });
            w = 1;
        });

        $('input:text[name="wallet"]').focus(function(){
            $('input:checkbox[name="use_balance"]').prop('checked', true);
//            $('input:checkbox[name="use_balance"]').each(function(){$(this).attr('checked', 'checked')});
            $('input:radio[name="payment_method"]').each(function(){
                if($(this).val() == 5){
                    $(this).attr('disabled', true);
                    $(this).attr('checked', false);
                    $(this).parent().css('color','#cccccc');
                }
            });
            w = 1;
        });
    });

    function OnInput (event) {
        var this_price = event.target.value;
        var pay_price = 0;
        var balance = 0;
        var wallet = 0;
        if(this_price < 0 || isNaN(this_price) || this_price == '') {
            this_price = 0;
            $('input:text[name="wallet"]').val(this_price);
        }
        pay_price = (total_price - this_price).toFixed(2);
        balance = (use_balance - this_price).toFixed(2);
        wallet = (wallet_amount + parseFloat(this_price)).toFixed(2);

        if(this_price > total_price && this_price <= use_balance){
            $('input:text[name="wallet"]').val(total_price);
            this_price = total_price.toFixed(2);
            pay_price = 0;
            balance = (use_balance - this_price).toFixed(2);
            wallet = (wallet_amount + parseFloat(this_price)).toFixed(2);
        }else if(this_price > use_balance && this_price <= total_price){
            $('input:text[name="wallet"]').val(use_balance);
            this_price = use_balance.toFixed(2);
            pay_price = (total_price - this_price).toFixed(2);
            balance = 0;
            wallet = (wallet_amount + parseFloat(this_price)).toFixed(2);
        }else if(this_price > use_balance && this_price > total_price){
            if(total_price >= use_balance){
                $('input:text[name="wallet"]').val(use_balance);
                this_price = use_balance.toFixed(2);
                pay_price = (total_price - this_price).toFixed(2);
                balance = 0;
                wallet = (wallet_amount + parseFloat(this_price)).toFixed(2);
            }else{
                $('input:text[name="wallet"]').val(total_price);
                this_price = total_price.toFixed(2);
                pay_price = 0;
                balance = (use_balance - this_price).toFixed(2);
                wallet = (wallet_amount + parseFloat(this_price)).toFixed(2);
            }
        }

        $('.span_total_price').html(pay_price);
        $('.span_wallet_amount').html(wallet);
        $('.usable_balance').html(balance);
        $('input:hidden[name="total_price"]').val(pay_price);
        $('input:hidden[name="wallet_amount"]').val(this_price);
    }

    function OnPropChanged (event) {
        if (event.propertyName.toLowerCase () == "value") {
            var this_price = event.srcElement.value;
            var pay_price = 0;
            var balance = 0;
            var wallet = 0;
            if(this_price < 0 || isNaN(this_price) || this_price == '') {
                this_price = 0;
                $('input:text[name="wallet"]').val(this_price);
            }
            pay_price = (total_price - this_price).toFixed(2);
            balance = (use_balance - this_price).toFixed(2);
            wallet = (wallet_amount + parseFloat(this_price)).toFixed(2);

            if(this_price > total_price && this_price <= use_balance){
                $('input:text[name="wallet"]').val(total_price);
                this_price = total_price.toFixed(2);
                pay_price = 0;
                balance = (use_balance - this_price).toFixed(2);
                wallet = (wallet_amount + parseFloat(this_price)).toFixed(2);
            }else if(this_price > use_balance && this_price <= total_price){
                $('input:text[name="wallet"]').val(use_balance);
                this_price = use_balance.toFixed(2);
                pay_price = (total_price - this_price).toFixed(2);
                balance = 0;
                wallet = (wallet_amount + parseFloat(this_price)).toFixed(2);
            }else if(this_price > use_balance && this_price > total_price){
                if(total_price >= use_balance){
                    $('input:text[name="wallet"]').val(use_balance);
                    this_price = use_balance.toFixed(2);
                    pay_price = (total_price - this_price).toFixed(2);
                    balance = 0;
                    wallet = (wallet_amount + parseFloat(this_price)).toFixed(2);
                }else{
                    $('input:text[name="wallet"]').val(total_price);
                    this_price = total_price.toFixed(2);
                    pay_price = 0;
                    balance = (use_balance - this_price).toFixed(2);
                    wallet = (wallet_amount + parseFloat(this_price)).toFixed(2);
                }
            }

            $('.span_total_price').html(pay_price);
            $('.span_wallet_amount').html(wallet);
            $('.usable_balance').html(balance);
            $('input:hidden[name="total_price"]').val(pay_price);
            $('input:hidden[name="wallet_amount"]').val(this_price);
        }
    }
</script>
</body>
</html>
